//
//  VideoCollectionViewCell.m
//  BasketballClub
//
//  Created by dhz on 16/1/15.
//  Copyright © 2016年 孙鸿吉. All rights reserved.
//

#import "VideoCollectionViewCell.h"
#import "VideoModel.h"
#import <UIImageView+WebCache.h>
#import <AVOSCloud.h>
@implementation VideoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self allViews];
    }
    return self;
}
#pragma mark  - 布局子视图
-(void)allViews
{
    
    self.imageV = [[UIImageView alloc]initWithFrame:CGRectMake(2*LAYOUT_SIZE, 2*LAYOUT_SIZE_HEIGHT, 200*LAYOUT_SIZE, 120*LAYOUT_SIZE_HEIGHT)];
    self.imageV.userInteractionEnabled = YES;
    [self.contentView addSubview:self.imageV];
    
    self.timeLabel = [[ UILabel alloc]initWithFrame:CGRectMake(165 * LAYOUT_SIZE, 105 * LAYOUT_SIZE_HEIGHT , 35 * LAYOUT_SIZE, 15 * LAYOUT_SIZE_HEIGHT)];
    self.timeLabel.backgroundColor  =[UIColor blackColor];
    self.timeLabel.textAlignment = 1;
    self.timeLabel.font = [UIFont systemFontOfSize:10 * LAYOUT_SIZE];
    self.timeLabel.textColor = [UIColor whiteColor];
    [self.imageV addSubview:self.timeLabel];
    
    self.readNumberImage = [[UIImageView alloc]initWithFrame:CGRectMake(2*LAYOUT_SIZE, 168*LAYOUT_SIZE_HEIGHT, 25*LAYOUT_SIZE, 25*LAYOUT_SIZE_HEIGHT)];
    self.readNumberImage.image = [UIImage imageNamed:@"iconfont-yanjing"];
    [self.contentView addSubview:self.readNumberImage];
    
    self.title = [[UILabel alloc]initWithFrame:CGRectMake(2*LAYOUT_SIZE, 120*LAYOUT_SIZE_HEIGHT, 200*LAYOUT_SIZE, 40*LAYOUT_SIZE_HEIGHT)];
    self.title.numberOfLines = 0;
    self.title.font  = [UIFont fontWithName:@"Helvetica-Bold" size:15 * LAYOUT_SIZE];
    [self.contentView addSubview:self.title];
    
    self.countLabel = [[UILabel alloc]initWithFrame:CGRectMake(30*LAYOUT_SIZE, 168*LAYOUT_SIZE_HEIGHT, 40*LAYOUT_SIZE, 25*LAYOUT_SIZE_HEIGHT)];
    self.countLabel.textAlignment = 0;
    self.countLabel.textColor = [UIColor lightGrayColor];
    self.countLabel.font = [UIFont systemFontOfSize:14*LAYOUT_SIZE];
    [self.contentView addSubview:self.countLabel];

    self.FButton = [[UIButton alloc]initWithFrame:CGRectMake(140*LAYOUT_SIZE, 165*LAYOUT_SIZE_HEIGHT, 25*LAYOUT_SIZE, 25*LAYOUT_SIZE_HEIGHT)];
    [self.FButton setImage:[UIImage imageNamed:@"iconfont-collect_act"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.FButton];
    
    
    self.share = [[UIButton alloc]initWithFrame:CGRectMake(172*LAYOUT_SIZE, 168*LAYOUT_SIZE_HEIGHT, 25*LAYOUT_SIZE, 25*LAYOUT_SIZE_HEIGHT)];
    [self.share setImage:[UIImage imageNamed:@"iconfont-zhuanfa"] forState:UIControlStateNormal];
    [self.contentView addSubview:self.share];
    
}

-(void)setCellDataWithModel:(VideoModel*)model
{
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:model.imglink]];
    self.timeLabel.text = [NSString stringWithFormat:@"%@",model.duration];
    self.countLabel.text  = [NSString stringWithFormat:@"%@",model.readarts];
    self.title.text = model.title;
    self.videoUrl = model.videolink;
    AVUser *current = [AVUser currentUser];
    NSString *key = [NSString stringWithFormat:@"%@%@",model.title,current.username];
    BOOL isCollect = [[LeanCloudService shareService] isCollectForKey:key];
    if (isCollect == YES) {
        [self.FButton setImage:[UIImage imageNamed:@"iconfont-htmal5icon24"] forState:UIControlStateNormal];
        self.FButton.userInteractionEnabled = NO;
    }else{
        [self.FButton setImage:[UIImage imageNamed:@"iconfont-collect_act"] forState:UIControlStateNormal];
        self.FButton.userInteractionEnabled = YES;
    }

}


@end
